package cn.stylefeng.guns.modular.system.service.ActivityEvent;

import cn.stylefeng.guns.modular.system.entity.DispatchOrder;
import cn.stylefeng.guns.modular.system.entity.UpShop;
import cn.stylefeng.guns.modular.system.service.DispatchOrderService;
import cn.stylefeng.guns.modular.system.service.UpShopService;
import cn.stylefeng.guns.sys.core.util.utility.StatusCode;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @Author : xiaofei
 * @Date: 2019/7/27
 */

public class ShiOponStoreEnvent implements ExecutionListener {

    private UpShopService upShopService = SpringContextHolder.getBean(UpShopService.class);

    @Override
    public void notify(DelegateExecution delegateExecution) {

        String eventName = delegateExecution.getEventName();
        UpShop upShop = upShopService.getOne(new QueryWrapper<UpShop>()
                .lambda().eq(UpShop::getProcessInstanceId,delegateExecution.getProcessInstanceId()));
        if ("end".equals(eventName)){
            upShop.setCheckCode(StatusCode.FAIL.getVal());
        }else if ("start".equals(eventName)){
            upShop.setCheckCode(StatusCode.SUCCESS.getVal());
        }
        upShopService.getBaseMapper().updateById(upShop);
    }



}
